package leetcode.leetcode100;

public class findMedianSortedArrays {
    public static void main(String[] args) {
        int[] nums1 = {1,3};
        int[] nums2 = {2,4};
        System.out.println(process(nums1,nums2));
    }
    public static double process(int[] nums1,int[] nums2){
        int[] merge = new int[nums1.length+nums2.length];
        int cur1 = 0;
        int cur2 = 0;
        int i =0;
        double ans = 0.0;
        while (cur1 < nums1.length && cur2 < nums2.length){
            merge[i++] = nums1[cur1]<=nums2[cur2]?nums1[cur1++]:nums2[cur2++];
        }
        while (cur1<nums1.length){
            merge[i++] = nums1[cur1++];
        }
        while (cur2<nums2.length){
            merge[i++] = nums2[cur2++];
        }
        if ((merge.length & 1) == 0){
            ans = (merge[(merge.length-1)/2]+merge[merge.length/2])/2.0;
        }else {
            ans = merge[(merge.length-1)/2];
        }
        return ans;
    }

}
